public class SeqStack<E> {
    private E[] data;
    private int top;

    public SeqStack(){
        data = (E[])new Object[10];
        top = -1;
    }

    public boolean empty(){
        return top==-1;
    }

    public void push(E e){
        if(top == data.length-1){
            updata((top+1)*2);
        }
        top++;
        data[top] = e;
    }

    public E pop(){
        if(empty()){
            throw new IllegalArgumentException("栈为空");
        }
        E ret = data[top];
        top--;

        if(top+1>10&&top+1==(data.length/4)){
            updata(data.length/2);
        }
        return ret;
    }

    public E top(){
        if(empty()){
            throw new IllegalArgumentException("栈为空");
        }
        return data[top];
    }

    public void updata(int size){
        E[] newdata = (E[]) new Object[size];
        for(int i = 0;i< data.length;i++){
            newdata[i] = data[i];
        }
        data = newdata;
    }
}
